{# SPDX-License-Identifier: Apache-2.0 -#}

{% extends "admin/base.html" %}

{% import "admin/utils/pagination.html" as pagination %}

{% block title %}Users{% endblock %}

{% block breadcrumb %}
  <li class="breadcrumb-item active">Users</li>
{% endblock %}

{% block content %}
<div class="card">
  <div class="card-body">
    <form>
      <div class="input-group input-group-lg">
        <input name="q" type="text" class="form-control input-lg" placeholder="Search"{% if query %} value="{{ query }}"{% endif %}>
        <div class="input-group-btn input-group-append">
          <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
        </div>
      </div>
    </form>
  </div>
  <div class="card-footer">
    <div class="row">
      <span class="small">
        Search defaults to username. Prefix search with <code>email:</code> or <code>id:</code> for specific searches.
      </span>
    </div>
  </div>
</div>

<div class="card">
  <div class="card-body table-responsive p-0">
    <table class="table table-striped table-hover">
      <thead>
      <tr>
        <th>Image</th>
        <th>Username</th>
        <th>Name</th>
        <th>Email</th>
        <th>PyPI Roles</th>
        <th>Active</th>
        <th>2FA</th>
        <th>Frozen</th>
      </tr>
      </thead>
      <tbody>
      {% for user in users %}
      <tr>
        <td><img src="{{ gravatar(request, user.email, size=20) }}" class="img-circle" alt="User Image"></td>
        <td>
          <a href="{{ request.route_path('admin.user.detail', username=user.username) }}">{{ user.username }}</a>
        </td>
        <td>{{ user.name }}</td>
        <td>{{ user.email }}</td>
        <td>
          {% set pypi_roles = [] %}
          {% if user.is_superuser %}{% set _ = pypi_roles.append("Admin") %}{% endif %}
          {% if user.is_moderator %}{% set _ = pypi_roles.append("Moderator") %}{% endif %}
          {% if user.is_psf_staff %}{% set _ = pypi_roles.append("PSF Staff") %}{% endif %}
          {% if user.is_observer %}{% set _ = pypi_roles.append("Observer") %}{% endif %}
          {% if user.is_support %}{% set _ = pypi_roles.append("Support") %}{% endif %}
          {{ pypi_roles|join(', ') }}
        </td>
        <td>{% if user.is_active %}<i class="fa fa-check text-green"></i>{% endif %}</td>
        <td>{% if user.has_two_factor %}<i class="fa fa-check text-green"></i>{% endif %}</td>
        <td>{% if user.is_frozen %}<i class="fa fa-check text-red"></i>{% endif %}</td>
      </tr>
      {% endfor %}
      </tbody>
    </table>
  </div>

  <div class="card-footer">
    <div class="row">
      <div class="col-sm-5">
        {{ pagination.summary(users) }}
      </div>

      <div class="col-sm-7">
        <div class="float-right">
          {{ pagination.paginate(users) }}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock content %}
